import { ArgumentMetadata, HttpException, HttpStatus, Injectable, PipeTransform } from '@nestjs/common';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator'
@Injectable()
export class UserAcountPipe implements PipeTransform {
  async transform(value: any, metadata: ArgumentMetadata) {
    // console.log(value, metadata);
    const DTO = plainToInstance(metadata.metatype, value)
    // console.log(DTO, 'DTO');
    const errors = await validate(DTO)
    if (errors.length) {
      throw new HttpException(errors, HttpStatus.BAD_REQUEST)
    }

    return value;
  }
}
